package com.syni.mdd.yhd.common.all.dao.jpa;

import com.syni.mdd.yhd.common.all.dao.BaseJPADao;
import com.syni.mdd.yhd.common.all.entity.BmsLocalLifeGoods;
import com.syni.mdd.yhd.common.all.entity.BmsLocalLifeGoodsRelation;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Map;
import java.util.Set;

public interface BmsLocalLifeGoodsRelationDao extends BaseJPADao<BmsLocalLifeGoodsRelation,Integer> {

    List<BmsLocalLifeGoodsRelation> findByLocalLifeId(Integer lifeId);

    @Query(value = "SELECT a.local_life_id,min(b.goods_price) FROM (SELECT * FROM bms_local_life_goods_relation WHERE local_life_id IN (?1)) a " +
            "JOIN bms_local_life_goods b ON a.local_life_goods_id = b.id and b.is_delete = 0 GROUP BY a.local_life_id ",nativeQuery = true)
    List<Map<Integer,Object>> getMinMoney(Set<Integer> lifeIds);

}
